package com.service;

import static com.def.GenericDef.RETURN_CODE_OK;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.dao.IBisMItemDao;
import com.dao.IRetPrdInfoDao;
import com.dao.IRetWODao;
import com.dao.ISpcRetMfgDataDao;
import com.icim.service.ICIMBaseService;
import com.model.Ret_prd_info;
import com.model.Ret_wo;
import com.model.Spc_ret_mfg_data;
import com.model.Spc_ret_mfg_dataId;
import com.tx.Xpcmsrdt.XpcmsrdtI;
import com.tx.Xpcmsrdt.XpcmsrdtIA;
import com.tx.Xpcmsrdt.XpcmsrdtO;
import com.tx.Xpspcchk.XpspcchkI;
import com.tx.Xpspcchk.XpspcchkIA;
import com.tx.Xpspcchk.XpspcchkO;
import com.util.GUIDGenerator;
import com.util.GUIDGenerator16;
import com.util.MqOpe;
import com.util.Util;

@Scope("prototype")
@Service("XpcmsrdtService")
public class XpcmsrdtService extends ICIMBaseService {
	private static final Logger logger = Logger.getLogger(XpcmsrdtService.class);
	@Autowired
	XpcmsrdtI inTrx;
	@Autowired
	XpcmsrdtO outTrx;

	@Autowired
	IRetPrdInfoDao retPrdInfoDao;
	@Autowired
	IBisMItemDao bisMItemDao;
	@Autowired
	ISpcRetMfgDataDao spcRetMfgDataDao;

	@Autowired
	IRetWODao retWoDao;

	@Autowired
	private XpspcchkService xpspcchkService;

	private Timestamp gsTimestamp;
	private String gsEvtSequenceID;
	private final long _NORMAL = 0;
	private final long E_NOT_FOUND_SHT = 1;
	private final long E_NOT_FOUND_WO = 2;
	private String gszMsgBuf = "";

	public String subMainProc(String strInMsg) {
		MqOpe mqOpe = new MqOpe();
		String reply = "";
		outTrx.setTrx_id("XPCMSRDT");
		outTrx.setType_id("O");
		try {
			logger.info("InTrx is " + strInMsg);
			inTrx = (XpcmsrdtI) mqOpe.inStr2Obj(strInMsg, inTrx);
			long lRc = SubMainProc2();
			if (lRc != _NORMAL) {
				outTrx.setRtn_code("000000" + lRc);
				outTrx.setRtn_msg(gszMsgBuf);
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			}
			outTrx.setRtn_code("0000000");
			outTrx.setRtn_msg("success");
			spcRetMfgDataDao.flushCurSession();
		} catch (Exception ex) {
			outTrx.setRtn_code("0000001");
			outTrx.setRtn_msg(ex.getMessage());
			logger.error(ex.getMessage());
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			return mqOpe.obj2Str(outTrx);
		} finally {
			reply = mqOpe.obj2Str(outTrx);
			logger.info(reply);
		}
		return reply;

	}

	public long SubMainProc2() {
		long lRc;
		MqOpe mqOpe = new MqOpe();
		String prdSeqId = inTrx.getPrd_seq_id();
		gsTimestamp = Util.getCurrentTimestamp();
		gsEvtSequenceID = GUIDGenerator16.javaGUID();

		//机台生成的CSV文件只存EDC，不送SPC
		if ("T".equals(inTrx.getRep_unit_fk())) {
			lRc = reportEqptSPCDatqa();
			return lRc;
		}

		Ret_prd_info retPrdInfo = (Ret_prd_info) retPrdInfoDao.get(prdSeqId);
		if (retPrdInfo == null) {
			gszMsgBuf = "not Found Record IN Ret_prd_info";
			logger.error(gszMsgBuf);
			return E_NOT_FOUND_SHT;
		}

		//for 1100 and 1400 thickness and resistance
		setPrdAdminFlgWhenCdpcCzpc(retPrdInfo);

		//report edc data
		lRc = setEDCDataValue(retPrdInfo);
		if (lRc != _NORMAL) {
			return lRc;
		}

		Ret_wo retWo = retWoDao.get(retPrdInfo.getWo_id_fk());
		if (retWo == null) {
			gszMsgBuf = "根据玻璃找不到工单信息[" + retPrdInfo.getWo_id_fk() + "]";
			logger.error(gszMsgBuf);
			return E_NOT_FOUND_WO;
		}

		XpspcchkO xpspcchkO = reportSPC(mqOpe, retPrdInfo, retWo);

		//TODO: if inTrx.check_spc_flg  does not equal("Y") , ignore the outTrx of xpspcchkService;
		if (!xpspcchkO.getRtn_code().equals(RETURN_CODE_OK)) {
			gszMsgBuf = xpspcchkO.getRtn_msg();
			return Integer.valueOf(xpspcchkO.getRtn_code());
		}

		return _NORMAL;
	}

	private XpspcchkO reportSPC(MqOpe mqOpe, Ret_prd_info retPrdInfo, Ret_wo retWo) {
		XpspcchkO xpspcchkO = new XpspcchkO();
		xpspcchkO.setTrx_id("XPSPCCHK");
		xpspcchkO.setTrx_id("O");

		XpspcchkI xpspcchkI = buildSpcInTrx(retPrdInfo, retWo);

		String strOutTrx = xpspcchkService.subMainProc(mqOpe.obj2Str(xpspcchkI));

		xpspcchkO = (XpspcchkO) mqOpe.inStr2Obj(strOutTrx, xpspcchkO);
		return xpspcchkO;
	}

	private XpspcchkI buildSpcInTrx(Ret_prd_info retPrdInfo, Ret_wo retWo) {

		XpspcchkI xpspcchkI = null;
		if ("Y".equals( inTrx.getCdpc_flg())) {
			xpspcchkI = buildCdpcSpcInTrx(retPrdInfo, retWo);
		} else {
			xpspcchkI = buildCommonSpcInTrx(retPrdInfo, retWo);
		}

		return xpspcchkI;
	}

	private XpspcchkI buildCdpcSpcInTrx(Ret_prd_info retPrdInfo, Ret_wo retWo) {

		//when the sheet is on unpack process ,get the from_thickness of it's work order,otherwise get the to_thickness;

		XpspcchkI xpspcchkI = buildCommonSpcInTrx(retPrdInfo, retWo);

		xpspcchkI.setCdpc_flg("Y");
		xpspcchkI.setTarget_thickness(inTrx.getTarget_thickness());
		xpspcchkI.setThickness_type(inTrx.getThickness_type());

		return xpspcchkI;
	}

	/**
	 * special CDPC process
	 * condition : if the inTrx was sent from page 1100 and 1400 and it's data_group is CDPC,
	 *             the cdpc_flg of inTrx will be Y
	 * action:  get the thickness of the sheet's work order then send to SPC.
	 *          the service XpspcchkService will find which chart's data_group is CDPC 
	 *          and it's target line equals the thickness of work oder,
	 *          pay attention!!!  XpspcchkService will ignore all the sub group condition,
	 *          so XpspcchkService may be heavily modified than expected;  
	 *          
	 */
	private XpspcchkI buildCommonSpcInTrx(Ret_prd_info retPrdInfo, Ret_wo retWo) {

		XpspcchkI xpspcchkI = new XpspcchkI();
		xpspcchkI.setTrx_id("XPSPCCHK");
		xpspcchkI.setType_id("O");

		xpspcchkI.setData_cnt(inTrx.getData_cnt());
		xpspcchkI.setClm_user(inTrx.getRpt_usr());
		xpspcchkI.setProd_seq_id(retPrdInfo.getPrd_seq_id());
		xpspcchkI.setCol_typ("2");//XXX : hard code
		xpspcchkI.setMdl_typ(retPrdInfo.getMdl_typ_fk());
		xpspcchkI.setMdl_cate(retPrdInfo.getMdl_cate_fk());
		xpspcchkI.setMdl_id(retPrdInfo.getMdl_id_fk());
		xpspcchkI.setP_tool_id(inTrx.getTool_id());
		xpspcchkI.setP_path_id(inTrx.getPath_id());
		xpspcchkI.setP_path_ver(inTrx.getPath_ver());
		xpspcchkI.setP_ope_no(inTrx.getOpe_no());
		xpspcchkI.setP_ope_id(inTrx.getOpe_id());
		xpspcchkI.setP_ope_ver(inTrx.getOpe_ver());
		xpspcchkI.setP_proc_id(inTrx.getProc_id());
		xpspcchkI.setM_tool_id(inTrx.getTool_id());
		xpspcchkI.setM_path_id(inTrx.getPath_id());
		xpspcchkI.setM_path_ver(inTrx.getPath_ver());
		xpspcchkI.setM_ope_no(inTrx.getOpe_no());
		xpspcchkI.setM_ope_id(inTrx.getOpe_id());
		xpspcchkI.setM_ope_ver(inTrx.getOpe_ver());
		xpspcchkI.setM_proc_id(inTrx.getProc_id());
		xpspcchkI.setEvt_usr(inTrx.getRpt_usr());
		xpspcchkI.setEvt_timestamp(gsTimestamp);
		if(StringUtils.isEmpty(inTrx.getLot_id())){
			xpspcchkI.setLot_id_fk(retPrdInfo.getLot_id());
		}else{
			xpspcchkI.setLot_id_fk(inTrx.getLot_id());
		}
		
		xpspcchkI.setWo_id_fk(retPrdInfo.getWo_id_fk());
		xpspcchkI.setCus_id_fk(retWo.getCus_id_fk());
		xpspcchkI.setSo_id_fk(retPrdInfo.getSo_id_fk());

		List<XpcmsrdtIA> edcIaryList = inTrx.getIary();
		List<XpspcchkIA> iaryList = new ArrayList<XpspcchkIA>();
		for (XpcmsrdtIA edcIary : edcIaryList) {
			XpspcchkIA iary = new XpspcchkIA();
			iary.setData_group(edcIary.getData_group());
			iary.setData_value(edcIary.getData_value());
			iary.setData_group_seq(edcIary.getData_group_seq());
			iaryList.add(iary);
		}

		xpspcchkI.setIary(iaryList);
		xpspcchkI.setData_cnt(inTrx.getData_cnt());

		return xpspcchkI;
	}

	private void setPrdAdminFlgWhenCdpcCzpc(Ret_prd_info retPrdInfo) {
		StringBuffer buffer = new StringBuffer(retPrdInfo.getPrd_admin_flg());

		if (("CDPC").equals(inTrx.getMes_id_fk())) {
			if (("NG").equals(inTrx.getJudgeStr())) {
				buffer.setCharAt(2, 'Y');
			} else {
				buffer.setCharAt(2, 'N');
			}
			retPrdInfo.setEvt_cate("CDPC");
		} else if (("CZPC").equals(inTrx.getMes_id_fk())) {
			if (("NG").equals(inTrx.getJudgeStr())) {
				buffer.setCharAt(3, 'Y');
			} else {
				buffer.setCharAt(3, 'N');
			}
			retPrdInfo.setEvt_cate("CZPC");
		}

		retPrdInfo.setPrd_admin_flg(buffer.toString());
		retPrdInfoDao.update(retPrdInfo);
	}

	public long setEDCDataValue(Ret_prd_info ret_prd_info) {
		int data_cnt = Integer.valueOf(inTrx.getData_cnt());
		List<XpcmsrdtIA> iaryList = inTrx.getIary();
		int data_seq_cnt = data_cnt / 30 + 1;
		int data_index = 0;
		int MAX_DATA_VALUE_CNT = 30;
		String prd_seq_id = inTrx.getPrd_seq_id();
		String tool_id_fk = inTrx.getTool_id();
		String rep_unit_fk = inTrx.getRep_unit_fk();
		String data_pat_fk = inTrx.getData_pat_fk();
		String mes_id_fk = inTrx.getMes_id_fk();
		String box_id_fk = ret_prd_info.getBox_id_fk();
		String slot_no_fk = ret_prd_info.getSlot_no();
		String path_id_fk = ret_prd_info.getCr_path_id_fk();
		String path_ver_fk = ret_prd_info.getCr_path_ver_fk();
		String ope_no_fk = ret_prd_info.getCr_ope_no_fk();
		String ope_id_fk = ret_prd_info.getCr_ope_id_fk();
		String ope_ver_fk = ret_prd_info.getCr_ope_ver_fk();
		String ds_recipe_id = "TODO";
		String ac_recipe_id = "TODO";
		String rpt_usr = inTrx.getRpt_usr();

		for (int i = 0; i < data_seq_cnt; i++) {
			Spc_ret_mfg_data spc_ret_mfg_data = new Spc_ret_mfg_data();
			Spc_ret_mfg_dataId id = new Spc_ret_mfg_dataId();
			id.setData_seq_id_fk(i + 1);
			id.setEvt_seq_id_fk(gsEvtSequenceID);
			id.setPrd_seq_id_fk(prd_seq_id);
			spc_ret_mfg_data.setId(id);
			spc_ret_mfg_data.setUnq_seq_id(GUIDGenerator.javaGUID());
			spc_ret_mfg_data.setTool_id_fk(tool_id_fk);
			spc_ret_mfg_data.setRep_unit_fk(rep_unit_fk);
			spc_ret_mfg_data.setData_pat_fk(data_pat_fk);
			spc_ret_mfg_data.setMes_id_fk(mes_id_fk);
			spc_ret_mfg_data.setBox_id_fk(box_id_fk);
			spc_ret_mfg_data.setSlot_no_fk(slot_no_fk);
			spc_ret_mfg_data.setPath_id_fk(path_id_fk);
			spc_ret_mfg_data.setPath_ver_fk(path_ver_fk);
			spc_ret_mfg_data.setOpe_id_fk(ope_id_fk);
			spc_ret_mfg_data.setOpe_no_fk(ope_no_fk);
			spc_ret_mfg_data.setOpe_ver_fk(ope_ver_fk);
			spc_ret_mfg_data.setDs_recipe_id(ds_recipe_id);
			spc_ret_mfg_data.setAc_recipe_id(ac_recipe_id);
			spc_ret_mfg_data.setRpt_usr(rpt_usr);
			spc_ret_mfg_data.setRpt_timestamp(gsTimestamp);
			spc_ret_mfg_data.setData_cnt(data_cnt);

			for (int j = 0; j < MAX_DATA_VALUE_CNT; j++) {
				data_index = i * MAX_DATA_VALUE_CNT + j;
				if (data_index == data_cnt) {
					break;
				}
				String data_value = iaryList.get(data_index).getData_value();
				if (j == 0) {
					spc_ret_mfg_data.setData_value_001(data_value);
				} else if (j == 1) {
					spc_ret_mfg_data.setData_value_002(data_value);
				} else if (j == 2) {
					spc_ret_mfg_data.setData_value_003(data_value);
				} else if (j == 3) {
					spc_ret_mfg_data.setData_value_004(data_value);
				} else if (j == 4) {
					spc_ret_mfg_data.setData_value_005(data_value);
				} else if (j == 5) {
					spc_ret_mfg_data.setData_value_006(data_value);
				} else if (j == 6) {
					spc_ret_mfg_data.setData_value_007(data_value);
				} else if (j == 7) {
					spc_ret_mfg_data.setData_value_008(data_value);
				} else if (j == 8) {
					spc_ret_mfg_data.setData_value_009(data_value);
				} else if (j == 9) {
					spc_ret_mfg_data.setData_value_010(data_value);
				} else if (j == 10) {
					spc_ret_mfg_data.setData_value_011(data_value);
				} else if (j == 11) {
					spc_ret_mfg_data.setData_value_012(data_value);
				} else if (j == 12) {
					spc_ret_mfg_data.setData_value_013(data_value);
				} else if (j == 13) {
					spc_ret_mfg_data.setData_value_014(data_value);
				} else if (j == 14) {
					spc_ret_mfg_data.setData_value_015(data_value);
				} else if (j == 15) {
					spc_ret_mfg_data.setData_value_016(data_value);
				} else if (j == 16) {
					spc_ret_mfg_data.setData_value_017(data_value);
				} else if (j == 17) {
					spc_ret_mfg_data.setData_value_018(data_value);
				} else if (j == 18) {
					spc_ret_mfg_data.setData_value_019(data_value);
				} else if (j == 19) {
					spc_ret_mfg_data.setData_value_020(data_value);
				} else if (j == 20) {
					spc_ret_mfg_data.setData_value_021(data_value);
				} else if (j == 21) {
					spc_ret_mfg_data.setData_value_022(data_value);
				} else if (j == 22) {
					spc_ret_mfg_data.setData_value_023(data_value);
				} else if (j == 23) {
					spc_ret_mfg_data.setData_value_024(data_value);
				} else if (j == 24) {
					spc_ret_mfg_data.setData_value_025(data_value);
				} else if (j == 25) {
					spc_ret_mfg_data.setData_value_026(data_value);
				} else if (j == 26) {
					spc_ret_mfg_data.setData_value_027(data_value);
				} else if (j == 27) {
					spc_ret_mfg_data.setData_value_028(data_value);
				} else if (j == 28) {
					spc_ret_mfg_data.setData_value_029(data_value);
				} else if (j == 29) {
					spc_ret_mfg_data.setData_value_030(data_value);
				}
			}
			spcRetMfgDataDao.save(spc_ret_mfg_data);
		}
		return _NORMAL;

	}

	public long reportEqptSPCDatqa() {
		int data_cnt = Integer.valueOf(inTrx.getData_cnt());
		List<XpcmsrdtIA> iaryList = inTrx.getIary();
		int data_seq_cnt = data_cnt / 30 + 1;
		int data_index = 0;
		int MAX_DATA_VALUE_CNT = 30;
		int id_cnt = 0;
		if (inTrx.getId_cnt() == null) {
			id_cnt = 0;
		}else{
			id_cnt = inTrx.getId_cnt().intValue();
		}
		if ( id_cnt == 0 ){
			for (int i = 0; i < data_seq_cnt; i++) {
				Spc_ret_mfg_data spc_ret_mfg_data = new Spc_ret_mfg_data();
				
				Spc_ret_mfg_dataId id = new Spc_ret_mfg_dataId();
				id.setData_seq_id_fk(i + 1);
				id.setEvt_seq_id_fk(gsEvtSequenceID);
				id.setPrd_seq_id_fk(inTrx.getPrd_seq_id());
				
				spc_ret_mfg_data.setId(id);
				spc_ret_mfg_data.setUnq_seq_id(GUIDGenerator.javaGUID());
				spc_ret_mfg_data.setTool_id_fk(inTrx.getTool_id());
				spc_ret_mfg_data.setRep_unit_fk(inTrx.getRep_unit_fk());
				spc_ret_mfg_data.setData_pat_fk(inTrx.getData_pat_fk());
				spc_ret_mfg_data.setMes_id_fk(inTrx.getMes_id_fk());
				spc_ret_mfg_data.setData_cnt(data_cnt);
				spc_ret_mfg_data.setRpt_usr(inTrx.getRpt_usr());
				spc_ret_mfg_data.setRpt_timestamp(gsTimestamp);

				for (int j = 0; j < MAX_DATA_VALUE_CNT; j++) {
					data_index = i * MAX_DATA_VALUE_CNT + j;
					if (data_index == data_cnt) {
						break;
					}
					String data_value = iaryList.get(data_index).getData_value();
					if (j == 0) {
						spc_ret_mfg_data.setData_value_001(data_value);
					} else if (j == 1) {
						spc_ret_mfg_data.setData_value_002(data_value);
					} else if (j == 2) {
						spc_ret_mfg_data.setData_value_003(data_value);
					} else if (j == 3) {
						spc_ret_mfg_data.setData_value_004(data_value);
					} else if (j == 4) {
						spc_ret_mfg_data.setData_value_005(data_value);
					} else if (j == 5) {
						spc_ret_mfg_data.setData_value_006(data_value);
					} else if (j == 6) {
						spc_ret_mfg_data.setData_value_007(data_value);
					} else if (j == 7) {
						spc_ret_mfg_data.setData_value_008(data_value);
					} else if (j == 8) {
						spc_ret_mfg_data.setData_value_009(data_value);
					} else if (j == 9) {
						spc_ret_mfg_data.setData_value_010(data_value);
					} else if (j == 10) {
						spc_ret_mfg_data.setData_value_011(data_value);
					} else if (j == 11) {
						spc_ret_mfg_data.setData_value_012(data_value);
					} else if (j == 12) {
						spc_ret_mfg_data.setData_value_013(data_value);
					} else if (j == 13) {
						spc_ret_mfg_data.setData_value_014(data_value);
					} else if (j == 14) {
						spc_ret_mfg_data.setData_value_015(data_value);
					} else if (j == 15) {
						spc_ret_mfg_data.setData_value_016(data_value);
					} else if (j == 16) {
						spc_ret_mfg_data.setData_value_017(data_value);
					} else if (j == 17) {
						spc_ret_mfg_data.setData_value_018(data_value);
					} else if (j == 18) {
						spc_ret_mfg_data.setData_value_019(data_value);
					} else if (j == 19) {
						spc_ret_mfg_data.setData_value_020(data_value);
					} else if (j == 20) {
						spc_ret_mfg_data.setData_value_021(data_value);
					} else if (j == 21) {
						spc_ret_mfg_data.setData_value_022(data_value);
					} else if (j == 22) {
						spc_ret_mfg_data.setData_value_023(data_value);
					} else if (j == 23) {
						spc_ret_mfg_data.setData_value_024(data_value);
					} else if (j == 24) {
						spc_ret_mfg_data.setData_value_025(data_value);
					} else if (j == 25) {
						spc_ret_mfg_data.setData_value_026(data_value);
					} else if (j == 26) {
						spc_ret_mfg_data.setData_value_027(data_value);
					} else if (j == 27) {
						spc_ret_mfg_data.setData_value_028(data_value);
					} else if (j == 28) {
						spc_ret_mfg_data.setData_value_029(data_value);
					} else if (j == 29) {
						spc_ret_mfg_data.setData_value_030(data_value);
					}
				}
				spcRetMfgDataDao.save(spc_ret_mfg_data);
			}
		}else {
			for (int k = 0; k < id_cnt ; k ++){
				for (int i = 0; i < data_seq_cnt; i++) {
					Spc_ret_mfg_data spc_ret_mfg_data = new Spc_ret_mfg_data();
					
					Spc_ret_mfg_dataId id = new Spc_ret_mfg_dataId();
					id.setData_seq_id_fk(i + 1);
					id.setEvt_seq_id_fk(gsEvtSequenceID);
					id.setPrd_seq_id_fk(inTrx.getIary_id().get(k).getPrd_seq_id_fk());
					
					spc_ret_mfg_data.setId(id);
					spc_ret_mfg_data.setUnq_seq_id(GUIDGenerator.javaGUID());
					spc_ret_mfg_data.setTool_id_fk(inTrx.getTool_id());
					spc_ret_mfg_data.setRep_unit_fk(inTrx.getRep_unit_fk());
					spc_ret_mfg_data.setData_pat_fk(inTrx.getData_pat_fk());
					spc_ret_mfg_data.setMes_id_fk(inTrx.getMes_id_fk());
					spc_ret_mfg_data.setData_cnt(data_cnt);
					spc_ret_mfg_data.setRpt_usr(inTrx.getRpt_usr());
					spc_ret_mfg_data.setRpt_timestamp(gsTimestamp);

					for (int j = 0; j < MAX_DATA_VALUE_CNT; j++) {
						data_index = i * MAX_DATA_VALUE_CNT + j;
						if (data_index == data_cnt) {
							break;
						}
						String data_value = iaryList.get(data_index).getData_value();
						if (j == 0) {
							spc_ret_mfg_data.setData_value_001(data_value);
						} else if (j == 1) {
							spc_ret_mfg_data.setData_value_002(data_value);
						} else if (j == 2) {
							spc_ret_mfg_data.setData_value_003(data_value);
						} else if (j == 3) {
							spc_ret_mfg_data.setData_value_004(data_value);
						} else if (j == 4) {
							spc_ret_mfg_data.setData_value_005(data_value);
						} else if (j == 5) {
							spc_ret_mfg_data.setData_value_006(data_value);
						} else if (j == 6) {
							spc_ret_mfg_data.setData_value_007(data_value);
						} else if (j == 7) {
							spc_ret_mfg_data.setData_value_008(data_value);
						} else if (j == 8) {
							spc_ret_mfg_data.setData_value_009(data_value);
						} else if (j == 9) {
							spc_ret_mfg_data.setData_value_010(data_value);
						} else if (j == 10) {
							spc_ret_mfg_data.setData_value_011(data_value);
						} else if (j == 11) {
							spc_ret_mfg_data.setData_value_012(data_value);
						} else if (j == 12) {
							spc_ret_mfg_data.setData_value_013(data_value);
						} else if (j == 13) {
							spc_ret_mfg_data.setData_value_014(data_value);
						} else if (j == 14) {
							spc_ret_mfg_data.setData_value_015(data_value);
						} else if (j == 15) {
							spc_ret_mfg_data.setData_value_016(data_value);
						} else if (j == 16) {
							spc_ret_mfg_data.setData_value_017(data_value);
						} else if (j == 17) {
							spc_ret_mfg_data.setData_value_018(data_value);
						} else if (j == 18) {
							spc_ret_mfg_data.setData_value_019(data_value);
						} else if (j == 19) {
							spc_ret_mfg_data.setData_value_020(data_value);
						} else if (j == 20) {
							spc_ret_mfg_data.setData_value_021(data_value);
						} else if (j == 21) {
							spc_ret_mfg_data.setData_value_022(data_value);
						} else if (j == 22) {
							spc_ret_mfg_data.setData_value_023(data_value);
						} else if (j == 23) {
							spc_ret_mfg_data.setData_value_024(data_value);
						} else if (j == 24) {
							spc_ret_mfg_data.setData_value_025(data_value);
						} else if (j == 25) {
							spc_ret_mfg_data.setData_value_026(data_value);
						} else if (j == 26) {
							spc_ret_mfg_data.setData_value_027(data_value);
						} else if (j == 27) {
							spc_ret_mfg_data.setData_value_028(data_value);
						} else if (j == 28) {
							spc_ret_mfg_data.setData_value_029(data_value);
						} else if (j == 29) {
							spc_ret_mfg_data.setData_value_030(data_value);
						}
					}
					spcRetMfgDataDao.save(spc_ret_mfg_data);
				}
			}
		}


		return _NORMAL;

	}
}
